
--Warning: Execute the StateInsertion.sql fllowed by DistrictInsertion.sql prior to this.

	
--Alter tables to allow null
ALTER TABLE [User] ALTER COLUMN AddedUserId INTEGER NULL
GO

--Update the tables set null to not null fields.
UPDATE [User] SET AddedUserId = NULL WHERE AddedUserId IS NOT NULL
GO

--Delete the existing contents
DELETE FROM RationCardAlterRequest
DELETE FROM RationCardAlterRequestType
DELETE FROM Unsubscription
DELETE FROM UnsubscriptionType
DELETE FROM [User]
DELETE FROM Roles
DELETE FROM PermanentAddress
GO

DBCC CHECKIDENT (UnsubscriptionType, RESEED, 0)
GO
INSERT INTO UnsubscriptionType(UnsubscriptionName)
	VALUES('AccountActivation')
INSERT INTO UnsubscriptionType(UnsubscriptionName)
	VALUES('VoterCardReminder')
GO

DBCC CHECKIDENT (RationCardAlterRequestType, RESEED, 0)
GO
INSERT INTO RationCardAlterRequestType(RationCardAlterRequestTypeName)
	VALUES('AddMember')
INSERT INTO RationCardAlterRequestType(RationCardAlterRequestTypeName)
	VALUES('RemoveMember')
GO
	
--Insert values to PermanentAddress
DBCC CHECKIDENT (PermanentAddress, RESEED, 0)
GO
INSERT INTO PermanentAddress(Address
							,PIN
							,DistrictId
							,City)
					values('RootAdmin Address'
						  ,0
						  ,1
						  ,'RootAdmin City')						  
GO

INSERT INTO PermanentAddress(Address
							,PIN
							,DistrictId
							,City)
					values('RootSuperAdmin Address'
						  ,0
						  ,1
						  ,'RootSuperAdmin City')
GO


--Insert Roles
INSERT INTO Roles VALUES(1, 'Person')
INSERT INTO Roles VALUES(2, 'Admin')
INSERT INTO Roles VALUES(3, 'SuperAdmin')
INSERT INTO Roles VALUES(4, 'Hospital')
GO

--Insert values to User
DBCC CHECKIDENT ([User], RESEED, 0)
GO
INSERT INTO [User](RoleId
				  ,UserName
				  ,Password
				  ,FirstName
				  ,MiddleName
				  ,PermanentAddressId
				  ,EmailAddress
				  ,PhoneNo
				  ,DateOfBirth
                  ,AddedDate)
		VALUES  (2
				,'RootAdmin'
				,'rootadmin'
				,'Root'
				,'Admin'
				,1
				,'knaveenbhat@gmail.com'
				,9008347658
				,GETDATE()
				,GETDATE())
GO

INSERT INTO [User](RoleId
				  ,UserName
				  ,Password
				  ,FirstName
				  ,MiddleName
				  ,PermanentAddressId
				  ,EmailAddress
				  ,PhoneNo
				  ,DateOfBirth
                  ,AddedDate)
		VALUES  (3
				,'RootSuperAdmin'
				,'rootsuperadmin'
				,'Root'
				,'SuperAdmin'
				,2
				,'knaveenbhat@gmail.com'
				,9008347658
				,GETDATE()
				,GETDATE())
GO

--Set the added users
UPDATE [User] SET AddedUserId = 2 WHERE AddedUserId IS NULL
GO

--Alter tables to not allow null
ALTER TABLE [User] ALTER COLUMN AddedUserId INTEGER NOT NULL
GO